#include "lib.h"

#include "kenoserv.h"

#include "GameConnection.h"

#include "casbase.h"

#include "log.h"
#include "opts.h"
#include "tracksql.h"

extern TrackSQL* g_tracker = NULL;

KenoServer::KenoServer(int port)
: Server(port,TEXT("Keno"))
{
	startTracker();
}

KenoServer::~KenoServer()
{
	stopTracker();
}

void
KenoServer::startTracker()
{
	ServerOpts::load();

	g_tracker = new TrackSQL(ServerOpts::dbdsn,
		ServerOpts::dblogin, ServerOpts::dbpasswd);

	// CSN-8891
	webServiceCall = new WebServiceCall();
}

void
KenoServer::stopTracker()
{
	delete g_tracker;
	g_tracker = 0;

	delete webServiceCall;
	webServiceCall = 0;
}

bool8
KenoServer::initSuccess()
{
	if (g_tracker && g_tracker->initOK())
		return Server::initSuccess();
	else
	{
		Log::msgError("Failed to connect to the database.  Aborting.");
		return false;
	}
}

Connection*
KenoServer::createConnection(SOCKET client)
{
	return new GameConnection(this, client);
}
